package cn.osworks.realtimemsg.spring;

import java.util.Date;

import javax.jms.JMSException;
import javax.jms.MapMessage;
import javax.jms.Message;
import javax.jms.Session;

import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;

import cn.osworks.aos.asset.AOSBeanLoader;
 
/**
 * <b>function:</b> Spring JMSTemplate 消息发送者
 */
public class Sender {
 
    public static void main(String[] args) {
        JmsTemplate jmsTemplate = (JmsTemplate) AOSBeanLoader.getSpringBean("jmsTemplate");        
        jmsTemplate.send(new MessageCreator() {
            public Message createMessage(Session session) throws JMSException {
                MapMessage message = session.createMapMessage();
                message.setString("text", "current system time: " + new Date().getTime());
                System.out.println("发送。");
                return message;
            }
        });
    }
}
